/****************************************************************************
 * Copyright (c) 2022 Qualcomm Technologies International, Ltd.
****************************************************************************/
/**
 * \defgroup atr_vad
 * \ingroup capabilities
 * \file  atr_vad.h
 *
 * Auto-Transparency VAD (ATR_VAD) operator public header file.
 *
 */

#ifndef _ATR_VAD_H_
#define _ATR_VAD_H_

/******************************************************************************
Include Files
*/

#include "capabilities.h"

#include "vad_handle.h"                 /* VAD security */

#include "base_aud_cur_op.h"            /* Class functions */
#include "atr_vad100_struct_public.h"   /* Library definitions */
#include "atr_vad100_public.h"          /* Library functions */

#include "atr_vad_gen_c.h"              /* Autogenerated ATR VAD definitions */
#include "atr_vad_defs.h"               /* Shared ATR VAD definitions */
#include "atr_vad_event.h"              /* ATR VAD event definitions */

/****************************************************************************
Public Variable Definitions
*/

extern const CAPABILITY_DATA atr_vad_cap_data; /* Capability data */

/******************************************************************************
Private Constant Definitions
*/

/* Number of statistics reported by the capability */
#define ATR_VAD_N_STAT                  (sizeof(ATR_VAD_STATISTICS)/sizeof(ParamType))

/* Mask for the number of system modes */
#define ATR_VAD_SYSMODE_MASK            0x7

/* Mask for override control word */
#define ATR_VAD_OVERRIDE_MODE_MASK      (0xFFFF ^ ATR_VAD_CONTROL_MODE_OVERRIDE)

#define ATR_VAD_MIN_VALID_SINKS         ((1 << ATR_VAD_BCM_TERMINAL))
#define ATR_VAD_MIN_VALID_SOURCES       0

/* Terminals to skip data propagation in base class */
#define ATR_VAD_TERMINAL_SKIP_MASK      0

#define ATR_VAD_SUPPORTS_IN_PLACE       TRUE
#define ATR_VAD_SUPPORTS_METADATA       TRUE
#define ATR_VAD_DYNAMIC_BUFFERS         FALSE

/* Capability minor version */
#define ATR_VAD_CAP_VERSION_MINOR       0

/******************************************************************************
Public Enums
*/

typedef enum
{
    ATR_VAD_UNUSED_TERMINAL,            /* 0 */
    ATR_VAD_BCM_TERMINAL,               /* 1 */
    ATR_VAD_FF_TERMINAL,                /* 2 */
    ATR_VAD_MAX_TERMINALS               /* 3 */
} ATR_VAD_TERMINALS;

/******************************************************************************
Public Type Declarations
*/

/* ATR_VAD operator data */
typedef struct atr_vad_exop
{
    unsigned sample_rate;               /* Operator sample rate */
    CAP_ID cap_id;                      /* Capability ID */
    ATR_VAD_PARAMETERS atr_vad_params;  /* Operator parameters */

    unsigned cur_mode;                  /* Current mode */
    unsigned ovr_control;               /* Override status */
    unsigned host_mode;                 /* Mode setting from apps/host */
    unsigned qact_mode;                 /* Mode setting from QACT */

    unsigned detect;                    /* Detection flags */
    ATR_VAD_RELEASE release_select;     /* Release selection */
    uint8 sensitivity_select;           /* Sensitivity selection */

    ATR_VAD_EVENT detect_event;         /* Detection event state machine */

    void *f_handle;                     /* Feature handle for licensing */

    tCbuffer *p_bcm_mic;                /* BCM mic buffer pointer */
    tCbuffer *p_ff_mic;                 /* FF mic buffer pointer */

    ATR_VAD100_DMX *p_atr_vad100;       /* Pointer to atr_vad100 module */
    uint8 *p_atr_vad100_dm1;            /* DM1 memory for atr_vad100 */
} ATR_VAD_OP_DATA;

/******************************************************************************
Private Function Definitions
*/

/* Standard Capability API handlers */
extern bool atr_vad_create(OPERATOR_DATA *op_data,
                           void *message_data,
                           unsigned *response_id,
                           void **resp_data);
extern bool atr_vad_destroy(OPERATOR_DATA *op_data,
                            void *message_data,
                            unsigned *response_id,
                            void **resp_data);

/* Standard Opmsg handlers */
extern bool atr_vad_opmsg_set_control(OPERATOR_DATA *op_data,
                                      void *message_data,
                                      unsigned *resp_length,
                                      OP_OPMSG_RSP_PAYLOAD **resp_data);
extern bool atr_vad_opmsg_get_status(OPERATOR_DATA *op_data,
                                     void *message_data,
                                     unsigned *resp_length,
                                     OP_OPMSG_RSP_PAYLOAD **resp_data);

/* Custom opmsg handlers*/
/**
 * \brief  Set the release duration value
 *
 * \param  op_data          Pointer to operator data
 * \param  message_data     Pointer to message data
 * \param  resp_length      Length of response
 * \param  resp_data        Pointer to response data
 *
 * \return  boolean indicating success or failure.
 *
 */
extern bool atr_vad_opmsg_set_release_duration(OPERATOR_DATA *op_data,
                                               void *message_data,
                                               unsigned *resp_length,
                                               OP_OPMSG_RSP_PAYLOAD **resp_data);

/**
 * \brief  Get the release duration value
 *
 * \param  op_data          Pointer to operator data
 * \param  message_data     Pointer to message data
 * \param  resp_length      Length of response
 * \param  resp_data        Pointer to response data
 *
 * \return  boolean indicating success or failure.
 *
 */
extern bool atr_vad_opmsg_get_release_duration(OPERATOR_DATA *op_data,
                                               void *message_data,
                                               unsigned *resp_length,
                                               OP_OPMSG_RSP_PAYLOAD **resp_data);

/**
 * \brief  Set the sensitivity
 *
 * \param  op_data          Pointer to operator data
 * \param  message_data     Pointer to message data
 * \param  resp_length      Length of response
 * \param  resp_data        Pointer to response data
 *
 * \return  boolean indicating success or failure.
 *
 */
extern bool atr_vad_opmsg_set_sensitivity(OPERATOR_DATA *op_data,
                                           void *message_data,
                                           unsigned *resp_length,
                                           OP_OPMSG_RSP_PAYLOAD **resp_data);

/**
 * \brief  Get the sensitivity
 *
 * \param  op_data          Pointer to operator data
 * \param  message_data     Pointer to message data
 * \param  resp_length      Length of response
 * \param  resp_data        Pointer to response data
 *
 * \return  boolean indicating success or failure.
 *
 */
extern bool atr_vad_opmsg_get_sensitivity(OPERATOR_DATA *op_data,
                                          void *message_data,
                                          unsigned *resp_length,
                                          OP_OPMSG_RSP_PAYLOAD **resp_data);

/* Standard data processing function */
extern void atr_vad_process_data(OPERATOR_DATA *op_data,
                                 TOUCHED_TERMINALS *touched);

/* Capability hook functions to work with base_aud_cur_op */
bool atr_vad_connect_hook(OPERATOR_DATA *op_data,
                          unsigned terminal_id);
bool atr_vad_disconnect_hook(OPERATOR_DATA *op_data,
                             unsigned terminal_id);

#endif /* _ATR_VAD_H_ */
